/**
 * Created by Chen on 2016/3/14.
 */
define(function(require, exports, module){

    var $ = require('jquery');
    var List = require('../../util/list.js');
    require('jquery.validate');
    require('jquery.icheck');
    require('bootstrap');
    require('bootstrap.select');
    require('jquery.layer');

    // 初始化
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
    });

    var cur_role = $("#curRole").val();

    $("#topic-submit").click(function(){
        var $form = $("#topic-form");
        if(!$form.valid()){
            return;
        }

        var postData = $form.serialize();

        var posting = $.post($CONFIG.base_url + "/api/topic/save", postData);
        posting.done(function(data) {
            if(data ==true) {
                layer.msg('保存成功', {
                    icon: 1,
                    time: 1000
                }, function () {
                    if(cur_role == 2) {
                        window.location.href = $CONFIG.base_url + "/teacher/topic/mine";
                    }
                    if(cur_role == 3) {
                        window.location.href = $CONFIG.base_url + "/student/topic/mine";
                    }
                });
            }
            if(data==false) {
                layer.msg('不能出题，您有题目正在审核中!',{
                    icon: 9,
                    time:4000
                },function(){
                    window.location.href = $CONFIG.base_url + "/student/topic/mine";
                });
            }

        });
    });


});
